package user;

import operation.*;

import java.util.Random;
import java.util.Scanner;

public class Customer extends User{

    public double balance;//余额

    public Customer() {
        operations = new IOperation[]{
                new Exit(),
                new Register(),
                new Login(),
                new Display()
        };
    }



    @Override
    public int menu() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("欢迎你,亲爱的顾客" +",祝你生活愉快");
        System.out.println("请选择操作>>");

        System.out.println("0 退出");
        System.out.println("2 注册");
        System.out.println("3 登录");
        System.out.println("4 查看");
        int choice = scanner.nextInt();
        return choice;
    }

    @Override
    public void electFunc(int choice) {
        operations[choice].work();
    }

    public void register() {
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();
        System.out.print("请输入昵称 : ");
        name = scanner.nextLine();
        System.out.print("请输入密码 ： ");
        password = scanner.nextInt();
        System.out.println("请再次确认密码");
        int tmp = scanner.nextInt();
        while (password != tmp) {
            System.out.println("两次密码不一致，请重新输入");
            tmp = scanner.nextInt();
        }
        account = random.nextInt(10000000);
        System.out.println("注册成功");
        System.out.println("昵称为" + name + "的用户，你好！" );
        System.out.println("你的账号和密码分别为,请保存");
        System.out.println("账号" + account);
        System.out.println("密码" + password);
    }



    public void login() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("欢迎登录 差一点就饿死了 外卖平台");
        System.out.println("请输入账号");
        int Account = scanner.nextInt();
        System.out.println("请输入密码");
        int Password = scanner.nextInt();
        while (Account != account || Password != password) {
            System.out.println("账号或密码错误，请重新输入");
        }
        System.out.println("登录成功");
        menu();

    }


    public void exit() {
        System.exit(0);
    }








}
